package com.fencing_squad.homo.slice;

import com.fencing_squad.homo.ResourceTable;
import com.fencing_squad.homo.util.Data;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.window.dialog.CommonDialog;
import ohos.multimodalinput.event.TouchEvent;

public class UserBalanceSlice extends AbilitySlice {
    Button exchange;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent((ComponentContainer) LayoutScatter.getInstance(this).parse(ResourceTable.Layout_balance, null, false));

        initConfig();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    private void initConfig() {
        exchange = (Button) findComponentById(ResourceTable.Id_exchange);
        exchange.setClickedListener(this::exchange);

        Text barTitle = (Text) findComponentById(ResourceTable.Id_barTitle);
        Component barBack = findComponentById(ResourceTable.Id_barBack);
        barTitle.setText("个人余额");
        barBack.setClickedListener(component -> {
            terminate();
        });

        Text point = (Text) findComponentById(ResourceTable.Id_point);
        Text money = (Text) findComponentById(ResourceTable.Id_money);
        point.setText(Data.Account.point + "分");
        money.setText(Data.Account.money + "元");
    }

    private void exchange(Component component) {
        present(new StoreSlice(), new Intent());
    }
}
